/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package foalvleditor.core.impl;

import foalvleditor.core.AbstractModel;
import foalvleditor.gameobjects.AbstractGameObject;
import foalvleditor.gameobjects.Bitmap;
import foalvleditor.gameobjects.GameEvent;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author Mikael
 */


/**
 * This class is part of MVC yet to be implemented.
 */

public class LevelModelMVC extends AbstractModel {

    private ArrayList<AbstractGameObject> level=
         new ArrayList<AbstractGameObject>();
    private boolean changed=false;
    private ArrayList<GameEvent> events=new ArrayList<GameEvent>();
    private String name="(Untitled)";
    private AbstractGameObject background;

    public void initDefault() {
        this.level=new ArrayList<AbstractGameObject>();
        this.events=new ArrayList<GameEvent>();
        this.name="(Untitled)";
        this.background=null;
        this.setChanged(false);
    }

    public boolean readyToClose(){
        if (this.hasChanged())
        {
            int really=JOptionPane.showConfirmDialog(null,
                    "The current level contains unsaved changes.\nDo you want to proceed?");
            if (really==JOptionPane.NO_OPTION) return false;
        }
        return true;
    }


    public void setChanged(boolean change){
        this.changed=change;
    }

    public boolean hasChanged(){
        return this.changed;
    }

    public ArrayList<AbstractGameObject> getLevel(){
        return level;
    }

    public void setLevel(ArrayList<AbstractGameObject> level){
        this.level=level;
    }

    public void addObject(AbstractGameObject goa){
        this.setChanged(true);
    }

    public void removeObject(AbstractGameObject object){
       level.remove(object);
       this.setChanged(true);
   }

    public void setName(String name){
        this.name=name;
        this.setChanged(true);
    }

    public String getName(){
        return this.name;
    }

    public boolean containsPlayer(){
        for (int i=0; i<level.size(); i++)
        {
            if (level.get(i).getName().contains("Player"))
            {
                return true;
            }
        }
        return false;
    }

    public void removeBackground(){
        this.background=null;
        this.setChanged(true);
    }

    public void setBackground(AbstractGameObject background){
        this.background=background;
        this.setChanged(true);
    }

    public AbstractGameObject getBackground(){
        return this.background;
    }


    public void addEvent(GameEvent event){
        events.add(event);
    }

    public void removeEvent(GameEvent event){
        events.remove(event);
    }

    public ArrayList<GameEvent> getEvents() {
        return this.events;
    }

    public void setEvents(ArrayList<GameEvent> parsedEvents) {
        this.events=parsedEvents;
    }

    public void setBitmap(AbstractGameObject obj, Bitmap bitmap) {
        obj.setBitmap(bitmap.getBitmapCode());
    }

}